<?
/**
* Copyright (c) 2002-2007 BioWare Corp.
* http://www.bigdaddymonitor.org
*
* This file is part of the BigDaddy Monitoring
* program. It is free software distributed under
* the terms of the BSD License. It is ditributed
* in the hopes that it will be useful, but
* WITHOUT ANY WARRANTY; without event the implied
* warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE.
*
* The BSD License is available from:
* http://www.opensource.org/licenses/bsd-license.php
**/
?>
<script language="javascript">

// -------------------------------------------------------------------
// swapOptions(select_object,option1,option2)
//  Swap positions of two options in a select list
// -------------------------------------------------------------------
function swapOptions(i,j) {
	//var o = obj.options;
	var i_selected = document.cat.elements['catlist[]'].options[i].selected;
	var j_selected = document.cat.elements['catlist[]'].options[j].selected;
	var temp = new Option(document.cat.elements['catlist[]'].options[i].text, document.cat.elements['catlist[]'].options[i].value, document.cat.elements['catlist[]'].options[i].defaultSelected, document.cat.elements['catlist[]'].options[i].selected);
	var temp2= new Option(document.cat.elements['catlist[]'].options[j].text, document.cat.elements['catlist[]'].options[j].value, document.cat.elements['catlist[]'].options[j].defaultSelected, document.cat.elements['catlist[]'].options[j].selected);
	document.cat.elements['catlist[]'].options[i] = temp2;
	document.cat.elements['catlist[]'].options[j] = temp;
	document.cat.elements['catlist[]'].options[i].selected = j_selected;
	document.cat.elements['catlist[]'].options[j].selected = i_selected;
	}


// -------------------------------------------------------------------
// moveOptionUp(select_object)
//  Move selected option in a select list up one
// -------------------------------------------------------------------
function moveOptionUp() {
	// If > 1 option selected, do nothing
	var selectedCount=0;
	for (i=0; i<document.cat.elements['catlist[]'].options.length; i++) {
		if (document.cat.elements['catlist[]'].options[i].selected) {
			selectedCount++;
			}
		}
	if (selectedCount > 1) {
		return;
		}
	// If this is the first item in the list, do nothing
	var i = document.cat.elements['catlist[]'].selectedIndex;
	if (i == 0) {
		return;
		}
	swapOptions(i,i-1);
	document.cat.elements['catlist[]'].options[i-1].selected = true;
	}

// -------------------------------------------------------------------
// moveOptionDown(select_object)
//  Move selected option in a select list down one
// -------------------------------------------------------------------
function moveOptionDown() {
	// If > 1 option selected, do nothing
	var selectedCount=0;
	for (i=0; i<document.cat.elements['catlist[]'].options.length; i++) {
		if (document.cat.elements['catlist[]'].options[i].selected) {
			selectedCount++;
			}
		}
	if (selectedCount > 1) {
		return;
		}
	// If this is the last item in the list, do nothing
	var i = document.cat.elements['catlist[]'].selectedIndex;
	if (i == (document.cat.elements['catlist[]'].options.length-1)) {
		return;
		}
	swapOptions(i,i+1);
	document.cat.elements['catlist[]'].options[i+1].selected = true;
	}

function callsubmit() {
	for (i=0; i<document.cat.elements['catlist[]'].options.length; i++) {
		document.cat.elements['catlist[]'].options[i].selected = true;
		
	}
	
	document.cat.submit();
}

</script>



<?
//$_SESSION["sessdata"]["displaymessage"]=display_message($_SESSION["sessdata"]["displaymessage"]);
?>
<br />

<p><b>Add a New Personal Link:</b></p>

<form method="post" action="query_quicklinks.php" name="addquicklinks">
    <table border="0" cellpadding="5" cellspacing="1" class="tablecolor1">
		<tr>
			<td class="tablecolor2"><b>Link Name:</b></td>
			<td class="tablecolor6"><input type="text" name="linkname" size="50" value="<?=$_SESSION["sessdata"]["linkname"];?>"/></td>
		</tr>
		<tr>
			<td class="tablecolor2"><b>Link URL:</b></td>
			<td class="tablecolor6"><input type="text" name="linkurl" size="50" value="<?=urldecode($_SESSION["sessdata"]["linkurl"]);?>"/></td>
		</tr>
    </table>
    <input type="hidden" name="action" value="addquicklinks" />
</form>

<br />

<button class="button2" onclick="javascript:document.addquicklinks.submit()" onmouseover="window.status='Add Quick Link!';return true;" onmouseout="window.status='';return true;">Add Quick Link</button>

<br /><br />
<hr />
<br />

<?
$sql="SELECT id, linkname, linkurl FROM quicklinks WHERE username='".LOGGEDIN_USERNAME."' ORDER BY ord";
$result=db_fetch_array(db_query($sql));

if (count($result)>0)
{
	?>
	<p><b>You current Personal Links:</b></p>
	
	<table border="0" cellpadding="5" cellspacing="1" class="tablecolor1">
		<tr align="left" class="tablecolor2">
			<td><b>Link Name</b></td>
			<td><b>Link URL</b></td>
			<td><b>Actions</b></td>
		</tr>
		
		<?	
		foreach ($result as $row)
		{
			?>
			<tr align="left" class="tablecolor6">
				<td><span class="smalltext"><?=$row["linkname"];?></span></td>
				<td><span class="smalltext"><?=urldecode($row["linkurl"]);?></span></td>
				<td><span class="smalltext">
					<a href="quicklinks.html?page=edit&id=<?=$row["id"];?>">Edit</a>
					/ <a href="query_quicklinks.php?action=deletequicklinks&id=<?=$row["id"];?>" onclick="javascript: return confirm('Are you sure you want to delete this Personal Link?')">Delete</a>
				</span></td>
			</tr>
			<?
		}
	
		?>
	</table>
	
	<?
}
else
{
	?>
	<p><b>You currently do not have any Personal Links.</b></p>
	<?
}
?>

<br />

<?

$sql="SELECT id, linkname FROM quicklinks WHERE username='".LOGGEDIN_USERNAME."' ORDER BY ord ASC";
$orderresult=db_fetch_array(db_query($sql));

if (count($orderresult)>0)
{
	?>
	<hr />
	<br />
	
	<p><b>Change the order of your Personal Links</b></p>
		
		<table border="0" cellpadding="5" cellspacing="1">
			<tr>
				<td>
					<form method="post" name="cat" action="<?=$_SERVER["PHP_SELF"];?>">
						<select name="catlist[]" size="<?=count($orderresult);?>" multiple>
							<?
							
							$i=1;
							foreach ($orderresult as $order)
							{
								echo "<option value=\"".$order["id"]."\">".$i.". ".$order["linkname"]."</option>";
								$i++;
							}
							?>
							
						</select>
						
						<br /><br />
						
						<input type="button" class="button3" value="Up" onClick="moveOptionUp()" id="input80" />
						<input type="button" class="button3" value="Down" onClick="moveOptionDown()" id="input80" />
						
						<br />
						
						<input type="hidden" name="proc" value="1" />
						<input type="button" class="button2" value="Submit" onclick="callsubmit()" />
						
					</form>	
				</td>
			</tr>
		</table>
	
	<?
}
?>

